<template>
<div class="documentprocess">
  <div>
    <el-breadcrumb @click="specialInitialProcess" separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/initiatingprocess' }" v-if="isShowItem">{{process[processNumber]}}</el-breadcrumb-item>
      <span @click.stop=";" v-if="isShowSpan">{{process[processNumber]}}<i class="el-icon-arrow-right"></i> </span>
      <span @click.stop=";">5-8单证流程</span>
    </el-breadcrumb>
  </div>

  <el-tabs v-model="tabValue" type="card" @tab-click="documentProcessChoose">
    <el-tab-pane label="工厂发货" name="1">
      <factoryDeliveryVue ref="fd"  @fromFD="udpateAllData" :tabOne="roles.documentprocess_fd_notice == 'W' ? true : false" :tabTwo="roles.documentprocess_fd_confirm == 'W' ? true : false" 
      :bus="bus"   :datas="saveData.documentprocess_fd"></factoryDeliveryVue>
    </el-tab-pane>
    <el-tab-pane label="单证员报关" name="2"  v-if="(processNumber == 0 || processNumber == 3) ? true : roles.documentprocess_cc !='H'">
      <documentMemberDeclaringCustomsVue @fromDC="udpateAllData"   :bus="bus"  :editable="roles.documentprocess_cc == 'W' ? true : false "  :datas="saveData.documentprocess_cc"></documentMemberDeclaringCustomsVue>
    </el-tab-pane>
    <el-tab-pane  label="向工厂索要发票" name="3" v-if=" (processNumber == 0 || processNumber == 3) ? true : roles.documentprocess_askInvoice !='H'">
      <ask-for-invoice :bus="bus" @fromAI="udpateAllData"  :editable="roles.documentprocess_askInvoice == 'W' ? true : false"  :datas="saveData.documentprocess_askInvoice" />
    </el-tab-pane>
    <el-tab-pane   label="核销资料收集" name="4" v-if="(processNumber == 0 || processNumber == 3) ? true : roles.documentprocess_collectionData !='H'">
      <collection-data :bus="bus"  @fromCD="udpateAllData"   :editable="roles.documentprocess_collectionData == 'W' ? true : false" :datas="saveData.documentprocess_collectionData" />
    </el-tab-pane>
  </el-tabs>

  <div class="documentprocess-fixed">
    <fixed-form v-if="hasBind" ref="fixedForm" :saveAndSend="saveAndSend" :datas="allData" :editable="editable" :sendMenus="sendMenus" processName="documentprocess" />
    <fixed-form v-else ref="fixedForm" :saveAndSend="false" :datas="allData" :editable="false" :sendMenus="sendMenus" processName="documentprocess" />
  </div>
</div>
</template>

<script>
import Vue from 'vue'
import factoryDeliveryVue from './factoryDelivery/factoryDeliveryVue.vue'
import documentMemberDeclaringCustomsVue from './documentMemberDeclaringCustoms/documentMemberDeclaringCustomsVue.vue'
import askForInvoice from './askForInvoiceToTheFactory/askForInvoiceToTheFactory.vue'
import collectionData from './collectionData/collectionData.vue'

import fixedForm from '../common/fixedForm.vue';

import {
  uploadFiles,
  getSendMenus,
  getData,
  getPermission
} from '@/server/initiatingprocess';
import {
  getStore,
  setStore
} from '@/assets/js/common'

export default {
  created() {
    let self = this;
    setStore("flow5-save-status", "unsave");
    this.allData = _.cloneDeep(this.saveData);

    this.bus = new Vue();
    this.bus.$on('bind-new-ftc', function(){
      self.hasBind = true;
    });

  },
  mounted() {
    //刷新浏览器时，避免重叠
    document.querySelector('.initiatingprocess  .routers-ctrl').style.zIndex = '-1';

    getSendMenus({
      'flowId': 5
    }).then((response) => {
      this.sendMenus = response.data.datas[0];
    });

    //判断面包屑二级路由是否可退回
    let isCreatFlow = getStore('isCreatFlow');
    this.isShowItem = !isCreatFlow ? false : true;
    this.isShowSpan = !isCreatFlow ? true : false;

  },
  beforeRouteEnter(to, from, next) {

    let dom = document.querySelector('.initiatingprocess  .routers-ctrl');
    if (dom) {
      dom.style.zIndex = '-1';
    }
    next(vm => {

      if (to.query.tab) {

        vm.tabValue = to.query.tab;

        // vm.$message({
        //   message: '请先绑定订单，否则无法保存和发送',
        //   type: 'warning',
        //   duration: 3000,
        //   showClose: true
        // });

        if (to.query.tab == 1) {
          let temp = vm.$children[1];
          // temp.$children[1].$children[0]工厂发货

          let cdi = temp.$children[1].$children[0];
          cdi.tabValue = to.query.subTab;

        }

        if (to.query.tab == 2) {
          let temp = vm.$children[1];
          // temp.$children[2].$children[0] 单证员报关
          let cdi = temp.$children[2].$children[0];
          cdi.tabValue = to.query.subTab;
        }


        /**
         * 获取显示tab的权限
         */

        let tabsPer = [
          {
            id: "#tab-1",
            show: true,
          }, {
            id: "#tab-2",
            show: true
          }, {
            id: "#tab-3",
            show: true
          }, {
            id: "#tab-4",
            show: true
          }
        ];

        let tabs = ["documentprocess_fd", "documentprocess_cc", "documentprocess_askInvoice", "documentprocess_collectionData"]

        getPermission({flowId: 5, currNodeId: ''}).then((response) => {

          let tabsPerData = response.data.datas[0];

          tabs.forEach((tabname,index) => {
            let temp = tabsPerData.find(e => e.itemName == tabname)
            if (temp.permission == 'H'){
              tabsPer[index].show = false;
            } else {
              tabsPer[index].show = true;
            }
          });

          //
          tabsPer.forEach(e => {
            if (e.show) {
              document.querySelector(e.id).style.display =  'inline-block';
            } else {
            document.querySelector(e.id).style.display =  'none';
            }
          })
        });
      }

      //从其他位置比如，待发，待办，或者已办等跳转过来
      if (to.query.dTab) {

        vm.processNumber = parseInt(to.query.itemStatus);

        vm.hasBind = true;

        vm.tabValue = '' + to.query.dTab;

        if (to.query.dTab == 1) {
          let temp = vm.$children[1];
          let cdi = temp.$children[1].$children[0];
          cdi.tabValue = '1';
        }

        if (to.query.tab == 2) {
          let temp = vm.$children[1];
          let cdi = temp.$children[2].$children[0];
          cdi.tabValue = '1';
        }

        let params = {
          flowId: to.query.flowId,
          currNodeId: to.query.currNodeId
        };


        if (to.query.isHive == 1) {

          getData({
            formInstId: to.query.formInstId,
            formServiceName: to.query.formServiceName,
            isHive: 1
          }).then((response) => {

            let data = response.data.datas[0];



            /**
             * 处理表格数据，返回为空的情况
             */

            if (data.documentprocess_fd.documentProcess_fd_notice.documentprocess_fdn_fc_dff_contacts.length === 0){
              data.documentprocess_fd.documentProcess_fd_notice.documentprocess_fdn_fc_dff_contacts = [{
                name: '',
                tel: '',
                email: '',
                qq: '',
                wechat: '',
                factoryName: ''
              }];
            }


            if (data.documentprocess_fd.documentProcess_fd_notice.documentprocess_fdn_lcc_dfl_contacts.length === 0){
              data.documentprocess_fd.documentProcess_fd_notice.documentprocess_fdn_lcc_dfl_contacts = [{
                name: '',
                tel: '',
                email: '',
                qq: '',
                wechat: '',
              }];
            }
            
            if (data.documentprocess_fd.documentProcess_fd_notice.documentprocess_deliDetail.length === 0){
              data.documentprocess_fd.documentProcess_fd_notice.documentprocess_deliDetail = [{
                dd_products: '',
                dd_description: '',
                dd_quantity: '',
                dd_price: '',
                dd_lineAmount: ''
              }];
            }   



            if (data.documentprocess_cc.documentprocess_cc_customsDeclarationInvoice.documentprocess_cc_cdi_table.length === 0){
              data.documentprocess_cc.documentprocess_cc_customsDeclarationInvoice.documentprocess_cc_cdi_table= [{
                documentprocess_cc_cdi_products: '',
                documentprocess_cc_cdi_description: '',
                documentprocess_cc_cdi_quantity: '',
                documentprocess_cc_cdi_price: '',
                documentprocess_cc_cdi_lineAmount: ''
              }];
            }   

     
            if (data.documentprocess_cc.documentprocess_cc_customsDeclarationBox.documentprocess_cc_cdb_table.length === 0){
              data.documentprocess_cc.documentprocess_cc_customsDeclarationBox.documentprocess_cc_cdb_table= [{
                documentprocess_cc_cdb_products: '', //产品
                documentprocess_cc_cdb_description: '', //描述
                documentprocess_cc_cdb_quantity: 0, //数量
                documentprocess_cc_cdb_packagenumber: '', //
                documentprocess_cc_cdb_netWeight: 0, //net weight
                documentprocess_cc_cdb_grossWeight: 0, //gross weight
                documentprocess_cc_cdb_measurement: 0 // measurement
              }];
            }   

            if (data.documentprocess_cc.documentprocess_cc_declarationForm.documentprocess_cc_df_table.length === 0){
              data.documentprocess_cc.documentprocess_cc_declarationForm.documentprocess_cc_df_table= [{
                  documentprocess_cc_df_productNO: '', //商品编号
                  documentprocess_cc_df_productName: '', //商品名称
                  documentprocess_cc_df_productDesc: '', //商品描述
                  documentprocess_cc_df_quantityAndUnit: [0, '个'], //数量个数 以及 单位
                  documentprocess_cc_df_weightAndUnit: [0, 'KGS'], //重量 以及 单位
                  documentprocess_cc_df_destnationContry: '', //最终运抵国
                  documentprocess_cc_df_price: '', //单价
                  documentprocess_cc_df_amount: '', //总价
                  documentprocess_cc_df_currency: '人民币', //货币
                  documentprocess_cc_df_LevyExemption: '照章', //征免
                  documentprocess_cc_df_countryOrigin: '', //原产国(新添属性)
              }];
            }   

            if (data.documentprocess_askInvoice.documentprocess_aski_table.length === 0){
              data.documentprocess_askInvoice.documentprocess_aski_table = [{
                documentprocess_aski_producuts: '',
                documentprocess_aski_description: '',
                documentprocess_aski_price: '',
                documentprocess_aski_quantity: '',
                documentprocess_aski_unit: '',
                documentprocess_aski_lineAmount: ''
              }];
            }  


            //对其中的字符串类型的附件名称，进行分割
            data = JSON.parse(JSON.stringify(data).replace(/(attachedFiles)/g, function(){return 'useless01';}).replace(/(attachedFileList)/g, function() {
              return "attachedFiles";
            }).replace(/(relationFormInst)/g, function(){ return 'relationFormInstId'}), function(k, v) {
              if (k === 'attachedFiles') {
                if (_.isArray(v)) {
                  return v.map((e) => {
                    return {
                      name: e.realFileName,
                      status: 1,
                      id: e.id
                    };
                  });
                } else {
                  return [];
                }
              }

              if (k === 'relationFormInstId'){
                if (_.isPlainObject(v)){
                  return [v];
                } else {
                  return [];
                }
              }

              if ((k.indexOf("_bindFContracts") != -1) || (k.indexOf("_bindDContracts") != -1)) {
                if (_.isString(v)){
                  return v.split(',');
                } else {
                  return [];
                }
              }

              // if ((k == 'documentprocess_cc_df_prodAndDesc') || (k == 'documentprocess_cc_df_quaAndWeight')){
              //   if (_.isString(v)){
              //     return v.split(',');
              //   } else {
              //     return [];
              //   }
              // }

              if ((k == 'documentprocess_cc_df_quantityAndUnit') || (k == 'documentprocess_cc_df_weightAndUnit')){
                if (_.isString(v)){
                  return v.split(',');
                } else {
                  return [];
                }
              }

              return v;
            });


            for (const key in data) {
              vm.$set(vm.saveData, key,  data[key]);
            }

            let approvalIndex, approvalFullName, names = [], originApprovals = _.cloneDeep(vm.saveData.originApprovals);

            if (data.role) {
              vm.editable = data.role.DEFAULT == 'W' ? true : false;

              for (var prop in vm.roles) {
                vm.$set(vm.roles, prop, data.role.DEFAULT);
              }

              /**
               * 处理 索要发票 组件的不显示，但是挂载
               */
              if ((vm.roles.documentprocess_cc !== 'H') && (vm.roles.documentprocess_askInvoice == 'H')){
                  let temp = _.cloneDeep(vm.roles);
                  temp.documentprocess_askInvoice = 'W';
                  vm.roles = temp;
                  document.querySelector("#tab-3").style.display =  'none';
              }


              vm.saveAndSend = vm.editable;
              let copyApprovals = _.cloneDeep(data.approvals);


              for (let i = 0; i < copyApprovals.length ; i++) {
                for (var prop in originApprovals[i]) {
                  if ((prop != 'rw') && (prop != 'approval_div_name') && (prop != 'item')){
                    originApprovals[i][prop] = copyApprovals[i][prop]
                  }
                }
              }
              vm.$set(vm.saveData, "originApprovals", originApprovals);
              vm.$set(vm.saveData, "isSalesMan", false);
            } else {
              vm.$set(vm.saveData, "isSalesMan", true);
            }

            getSendMenus(params).then((response) => {
              vm.sendMenus = response.data.datas[0];
              vm.allData = _.cloneDeep(vm.saveData);
            });

          });
        } else {

          getData({
            formInstId: to.query.formInstId,
            formServiceName: to.query.formServiceName
          }).then((response) => {

            let data = response.data.datas[0];


            /**
             * 处理表格数据，返回为空的情况
             */

            if (data.documentprocess_fd.documentProcess_fd_notice.documentprocess_fdn_fc_dff_contacts.length === 0){
              data.documentprocess_fd.documentProcess_fd_notice.documentprocess_fdn_fc_dff_contacts = [{
                name: '',
                tel: '',
                email: '',
                qq: '',
                wechat: '',
                factoryName: ''
              }];
            }


            if (data.documentprocess_fd.documentProcess_fd_notice.documentprocess_fdn_lcc_dfl_contacts.length === 0){
              data.documentprocess_fd.documentProcess_fd_notice.documentprocess_fdn_lcc_dfl_contacts = [{
                name: '',
                tel: '',
                email: '',
                qq: '',
                wechat: '',
              }];
            }
            
            if (data.documentprocess_fd.documentProcess_fd_notice.documentprocess_deliDetail.length === 0){
              data.documentprocess_fd.documentProcess_fd_notice.documentprocess_deliDetail = [{
                dd_products: '',
                dd_description: '',
                dd_quantity: '',
                dd_price: '',
                dd_lineAmount: ''
              }];
            }   



            if (data.documentprocess_cc.documentprocess_cc_customsDeclarationInvoice.documentprocess_cc_cdi_table.length === 0){
              data.documentprocess_cc.documentprocess_cc_customsDeclarationInvoice.documentprocess_cc_cdi_table= [{
                documentprocess_cc_cdi_products: '',
                documentprocess_cc_cdi_description: '',
                documentprocess_cc_cdi_quantity: '',
                documentprocess_cc_cdi_price: '',
                documentprocess_cc_cdi_lineAmount: ''
              }];
            }   

     
            if (data.documentprocess_cc.documentprocess_cc_customsDeclarationBox.documentprocess_cc_cdb_table.length === 0){
              data.documentprocess_cc.documentprocess_cc_customsDeclarationBox.documentprocess_cc_cdb_table= [{
                documentprocess_cc_cdb_products: '', //产品
                documentprocess_cc_cdb_description: '', //描述
                documentprocess_cc_cdb_quantity: 0, //数量
                documentprocess_cc_cdb_packagenumber: '', //
                documentprocess_cc_cdb_netWeight: 0, //net weight
                documentprocess_cc_cdb_grossWeight: 0, //gross weight
                documentprocess_cc_cdb_measurement: 0 // measurement
              }];
            }   

            if (data.documentprocess_cc.documentprocess_cc_declarationForm.documentprocess_cc_df_table.length === 0){
              data.documentprocess_cc.documentprocess_cc_declarationForm.documentprocess_cc_df_table= [{
                  documentprocess_cc_df_productNO: '', //商品编号
                  documentprocess_cc_df_productName: '', //商品名称
                  documentprocess_cc_df_productDesc: '', //商品描述
                  documentprocess_cc_df_quantityAndUnit: [0, '个'], //数量个数 以及 单位
                  documentprocess_cc_df_weightAndUnit: [0, 'KGS'], //重量 以及 单位
                  documentprocess_cc_df_destnationContry: '', //最终运抵国
                  documentprocess_cc_df_price: '', //单价
                  documentprocess_cc_df_amount: '', //总价
                  documentprocess_cc_df_currency: '人民币', //货币
                  documentprocess_cc_df_LevyExemption: '照章', //征免
                  documentprocess_cc_df_countryOrigin: '', //原产国(新添属性)
              }];
            }   

            if (data.documentprocess_askInvoice.documentprocess_aski_table.length === 0){
              data.documentprocess_askInvoice.documentprocess_aski_table = [{
                documentprocess_aski_producuts: '',
                documentprocess_aski_description: '',
                documentprocess_aski_price: '',
                documentprocess_aski_quantity: '',
                documentprocess_aski_unit: '',
                documentprocess_aski_lineAmount: ''
              }];
            }  


            //对其中的字符串类型的附件名称，进行分割
            data = JSON.parse(JSON.stringify(data).replace(/(attachedFiles)/g, function(){return 'useless01';}).replace(/(attachedFileList)/g, function() {
              return "attachedFiles";
            }).replace(/(relationFormInst)/g, function(){ return 'relationFormInstId'}), function(k, v) {
              if (k === 'attachedFiles') {
                if (_.isArray(v)) {
                  return v.map((e) => {
                    return {
                      name: e.realFileName,
                      status: 1,
                      id: e.id
                    };
                  });
                } else {
                  return [];
                }
              }
              if (k === 'relationFormInstId'){
                if (_.isPlainObject(v)){
                  return [v];
                } else {
                  return [];
                }
              }

              if ((k.indexOf("_bindFContracts") != -1) || (k.indexOf("_bindDContracts") != -1)) {
                if (_.isString(v)){
                  return v.split(',');
                } else {
                  return [];
                }
              }

              // if ((k == 'documentprocess_cc_df_prodAndDesc') || (k == 'documentprocess_cc_df_quaAndWeight')){
              //   if (_.isString(v)){
              //     return v.split(',');
              //   } else {
              //     return [];
              //   }
              // }

              if ((k == 'documentprocess_cc_df_quantityAndUnit') || (k == 'documentprocess_cc_df_weightAndUnit')){
                if (_.isString(v)){
                  return v.split(',');
                } else {
                  return [];
                }
              }
              return v;
            });


            for (const key in data) {
              vm.$set(vm.saveData, key,  data[key]);
            }


            let approvalIndex, approvalFullName, names = [], originApprovals = _.cloneDeep(vm.saveData.originApprovals);

            if (data.role) {
              data.role.forEach((e) => {
                if (e.itemName.indexOf("item") === -1) {
                  vm.$set(vm.roles, e.itemName, e.permission);
                } else {
                  let num = Number(e.itemName[e.itemName.length - 1]) - 1;
                  if (e.permission == 'W') {
                    approvalIndex = num;
                    approvalFullName = e.itemName;
                  }
                }
              });

              if (vm.roles.documentprocess_cc_letterOfDelivery == 'W'){
                vm.$set(vm.roles, 'documentprocess_cc', 'W');
              }

              vm.editable = true;
              vm.saveAndSend = true;

              let copyApprovals = _.cloneDeep(data.approvals);


              if (approvalIndex !== undefined) {
                if (approvalIndex >= 0) {
                  for (let i = 0; i <= approvalIndex; i++) {
                    if (copyApprovals[i]){
                      for (var prop in originApprovals[i]) {
                        if ((prop != 'rw') && (prop != 'approval_div_name') && (prop != 'item')){
                          originApprovals[i][prop] = copyApprovals[i][prop]
                        }
                      }
                      originApprovals[i].approval_id = '' + copyApprovals[i].id;
                    }
                  }
                }

                let date = new Date();
                originApprovals[approvalIndex].rw = 'W';
                originApprovals[approvalIndex].approval_time = date.toLocaleDateString() + ' ' + date.toTimeString().slice(0, 9);
                originApprovals[approvalIndex].approval_username = JSON.parse(getStore('userMsg')).userName;;

              } else if (copyApprovals.length > 0){
                for (let i = 0; i < copyApprovals.length; i++) {

                  for (var prop in originApprovals[i]) {
                    if ((prop != 'rw') && (prop != 'approval_div_name') && (prop != 'item')){
                      originApprovals[i][prop] = copyApprovals[i][prop]
                    }
                  }
                  originApprovals[i].approval_id = '' + copyApprovals[i].id;
                }
              }

              if ((vm.roles.documentprocess_cc !== 'H') && (vm.roles.documentprocess_askInvoice == 'H')){
                  let temp = _.cloneDeep(vm.roles);
                  temp.documentprocess_askInvoice = 'W';
                  vm.roles = temp;
                  document.querySelector("#tab-3").style.display =  'none';
              }

              vm.$set(vm.saveData, "originApprovals", originApprovals);
              vm.$set(vm.saveData, "isSalesMan", false);
            } else {
              vm.$set(vm.saveData, "isSalesMan", true);
            }

            getSendMenus(params).then((response) => {
              vm.sendMenus = response.data.datas[0];
              vm.allData = _.cloneDeep(vm.saveData);
            });

          });
        }
      }
    });
  },
  beforeRouteLeave(to, from, next){
    document.querySelector('.initiatingprocess  .routers-ctrl').style.zIndex = '-1';
    if (getStore("flow5-save-status") === 'unsave'){
      this.$confirm('您填写的内容尚未保存或发送,是否要离开?', '提示', {
        confirmButtonText: '离开',
        cancelButtonText: '留下',
        type: 'warning'
      }).then(() => {
        next();
      }).catch(() => {
        Array.prototype.forEach.call(document.getElementsByTagName('*'), (e) => {
          e.blur();
        });
        next(false);
      });
    } else {
      next();
    }
  },
  data() {
    return {
      saveData: {
        hasSaved: false,
        relationFormInstId: [], //关联订单

        isSalesMan: true,
        newApprovalName: '',

        //该流程中的所有审批项
        approvalNames: [
          "单证领导审批出厂确认", "风控审批出厂确认", "单证领导审批报关合同", "单证领导审批开票信息", "单证领导审批核销资料"
        ],

        newApproval: {
          "approval_opinion": "",
          "approval_username": "",
          "approval_time": "",
          "approval_div_name": ""
        },

        prevApprovals: [],

        //该流程中的所有审批项
        originApprovals: [
          {
            "approval_opinion": "",
            "approval_username": "",
            "approval_time": "",
            "approval_div_name": "单证领导审批出厂确认",
            "rw": 'R',
            item: 'item_05_01',
          }, {
            "approval_opinion": "",
            "approval_username": "",
            "approval_time": "",
            "approval_div_name": "风控审批出厂确认",
            "rw": 'R',
            item: 'item_05_02',
          }, {
            "approval_opinion": "",
            "approval_username": "",
            "approval_time": "",
            "approval_div_name": "单证领导审批报关合同",
            "rw": 'R',
            item: 'item_05_03',
          }, {
            "approval_opinion": "",
            "approval_username": "",
            "approval_time": "",
            "approval_div_name": "单证领导审批开票信息",
            "rw": 'R',
            item: 'item_05_04',
          }, {
            "approval_opinion": "",
            "approval_username": "",
            "approval_time": "",
            "approval_div_name": "单证领导审批核销资料",
            "rw": 'R',
            item: 'item_05_05',
          }
        ],

        //工厂发货
        documentprocess_fd: {

          //发货通知
          documentProcess_fd_notice: {
            id: '',
            formInstId: '',
            attachedFiles: [],

            //绑定的外贸订单id
            bindingFormInstId: '',

            orderCode: '',
            buyerName: '',
            documentprocess_fdn_bindFContracts: [],

            documentprocess_fdn_bindDContracts: [],

            documentprocess_fdn_contracts: '',


            //发货时间
            documentprocess_fdn_time: '',
            //交易方式
            documentprocess_fdn_tradeTerm: '',

            //海关编码
            documentprocess_fdn_hscode: '',

            //other
            documentprocess_fdn_other: '',

            //工厂联系方式
            documentprocess_fdn_fc_factoryName: '',
            documentprocess_fdn_fc_dff_contacts:[ 
              {
                name: '',
                tel: '',
                email: '',
                qq: '',
                wechat: '',
                factoryName: ''
              }],

            //物流联系方式
            documentprocess_fdn_lcc_logisticName: '',
            documentprocess_fdn_lcc_dfl_contacts: [
              {
                name: '',
                tel: '',
                email: '',
                qq: '',
                wechat: ''
              }
            ],

            documentprocess_deliDetail_total_number: '', //数量总和
            documentprocess_deliDetail_total_amount: '', //金额总和

            //发货明细
            documentprocess_deliDetail: [
              {
                dd_products: '',
                dd_description: '',
                dd_quantity: '',
                dd_price: '',
                dd_lineAmount: ''
              }
            ]
          },

          //出厂确认
          documentProcess_fd_confirm: {
            id: '',
            formInstId: '',
            attachedFiles: []
          }

        },

        //单证员报关
        documentprocess_cc: {

          //货运委托书
          documentprocess_cc_letterOfDelivery: {
            id: '',
            formInstId: '',
            attachedFiles: [], //附件
            documentprocess_cc_lod_from: '', //
            documentprocess_cc_lod_to: '',
            documentprocess_cc_lod_fax: '', //货代fax
            documentprocess_cc_lod_transport: '', //运输
            documentprocess_cc_lod_contractNO: '', //合同编号
            documentprocess_cc_lod_consignee: '', //收货人
            documentprocess_cc_lod_caddress: '', //收货地址
            documentprocess_cc_lod_ctel: '', //收货电话
            documentprocess_cc_lod_seafreightCH: '预付', //海洋运费 中文
            documentprocess_cc_lod_seafreightEN: 'PREPAID', //海洋运费 英文
            documentprocess_cc_lod_loadPort: '', //起运港
            documentprocess_cc_lod_destPort: '', //目的港
            documentprocess_cc_lod_containers: '', //集装箱配数
            documentprocess_cc_lod_shipDate: '', //装期
            documentprocess_cc_lod_shipMarks: '', //标记码
            documentprocess_cc_lod_numbers: '', //件数
            documentprocess_cc_lod_products: '', //产品名称
            documentprocess_cc_lod_weight: '', //毛重
            documentprocess_cc_lod_size: '', //尺寸
            documentprocess_cc_lod_tradeTerms: '', //交易方式
            documentprocess_cc_lod_doorToDoor: '', //门对门地址
            documentprocess_cc_lod_entry: '', //货物进仓
            documentprocess_cc_lod_signer: '', //签名
            documentprocess_cc_lod_backAddress: '', //退单地址
            documentprocess_cc_lod_rise: '', //开票抬头
            documentprocess_cc_lod_contact: '', //联系人
            documentprocess_cc_lod_contactTel: '', //联系电话
            documentprocess_cc_lod_contactFax: '', //传真
            documentprocess_cc_lod_date: '', //订单日期
          },

          //报关发票
          documentprocess_cc_customsDeclarationInvoice: {
            id: '',
            formInstId: '',
            attachedFiles: [], //附件
            documentprocess_cc_cdi_toName: '', //买方
            documentprocess_cc_cdi_toAdd: '', //买方地址
            documentprocess_cc_cdi_toTel: '', //买方电话
            documentprocess_cc_cdi_invoiceNO: '', //发票编号
            documentprocess_cc_cdi_invoiceDate: '', //发票日期
            documentprocess_cc_cdi_fromPort: '', //出发港
            documentprocess_cc_cdi_toPort: '', //目的港
            documentprocess_cc_cdi_shipDate: '', //装期
            documentprocess_cc_cdi_transport: '', //运输方式
            documentprocess_cc_cdi_payTerms: 'BY T/T', //付款方式
            documentprocess_cc_cdi_tradeTerms: '', //交易方式
            documentprocess_cc_cdi_currencyValue: '人民币', //币种

            documentprocess_cc_cdi_titleUP: 'Unit Price(USD)',
            documentprocess_cc_cdi_titleAm: 'Amount(USD)',

            documentprocess_cc_cdi_table_number: '', //数量和
            documentprocess_cc_cdi_table_amount: '', //金额总和

            documentprocess_cc_cdi_table: [
              {
                documentprocess_cc_cdi_products: '',
                documentprocess_cc_cdi_description: '',
                documentprocess_cc_cdi_quantity: '',
                documentprocess_cc_cdi_price: '',
                documentprocess_cc_cdi_lineAmount: ''
              }
            ]

          },

          //报关箱单
          documentprocess_cc_customsDeclarationBox: {
            id: '',
            formInstId: '',
            attachedFiles: [],
            documentprocess_cc_cdb_toName: '',
            documentprocess_cc_cdb_toAdd: '',
            documentprocess_cc_cdb_toTel: '',
            documentprocess_cc_cdb_invoiceNO: '',
            documentprocess_cc_cdb_invoiceDate: '',
            documentprocess_cc_cdb_fromPort: '',
            documentprocess_cc_cdb_toPort: '',
            documentprocess_cc_cdb_shipDate: '',
            documentprocess_cc_cdb_transport: '',
            documentprocess_cc_cdb_payTerms: 'BY T/T',
            documentprocess_cc_cdb_tradeTerms: '',

            documentprocess_cc_cdb_total_quantity: 0,
            documentprocess_cc_cdb_total_netWeight: 0, 
            documentprocess_cc_cdb_total_grossWeight: 0, 
            documentprocess_cc_cdb_total_measurement: 0, 

            documentprocess_cc_cdb_table: [
              {
                documentprocess_cc_cdb_products: '', //产品
                documentprocess_cc_cdb_description: '', //描述
                documentprocess_cc_cdb_quantity: 0, //数量
                documentprocess_cc_cdb_packagenumber: '', //
                documentprocess_cc_cdb_netWeight: 0, //net weight
                documentprocess_cc_cdb_grossWeight: 0, //gross weight
                documentprocess_cc_cdb_measurement: 0 // measurement
              }
            ],

            documentprocess_cc_cdb_totalPackage: 0,
            documentprocess_cc_cdb_totalPackageUnit: 'PKGS',
            documentprocess_cc_cdb_marks: '',
            documentprocess_cc_cdb_shipMarks: ''
          },

          //报关合同委托书
          documentprocess_cc_customsDeclarationContract: {
            id: '',
            formInstId: '',
            attachedFiles: [],
            documentprocess_cc_cdc_contractNO: '', //合同编号
            documentprocess_cc_cdc_contractDate: '', //签订日期
            documentprocess_cc_cdc_buyer: '', //买方
            documentprocess_cc_cdc_buyerAdd: '', //买方地址
            documentprocess_cc_cdc_buyerTel: '', //买方电话
            documentprocess_cc_cdc_description: '', //产品描述
            documentprocess_cc_cdc_quantitys: '', //产品数量
            documentprocess_cc_cdc_quantityUnit: 'PKGS', //产品数量单位
            documentprocess_cc_cdc_amounts: '', //产品金额
            documentprocess_cc_cdc_amounts_usd: 'USD', //金额单位
            documentprocess_cc_cdc_payTerms: '', //付款方式
            documentprocess_cc_cdc_shipDate: '', //装期
            documentprocess_cc_cdc_loadPort: '', //出发港
            documentprocess_cc_cdc_marks: '', //ship marks
            documentprocess_cc_cdc_destPort: '', //目的港
            documentprocess_cc_cdc_otherTerms: '',//other terms
            documentprocess_cc_cdc_insurance: 'TO BE COVERED BY BUYER ', //insurance
          },

          //报关单
          documentprocess_cc_declarationForm: {
            id: '',
            formInstId: '',
            attachedFiles: [], //附件
            documentprocess_cc_df_enterNO: '', //录入编号
            documentprocess_cc_df_hscode: '', //海关编号
            documentprocess_cc_df_company: '', //单位
            documentprocess_cc_df_exportPort: '', //出口口岸
            documentprocess_cc_df_exportDate: '', //出口日期
            documentprocess_cc_df_applyDate: '', //申请日期
            documentprocess_cc_df_transport: '', //运输方式
            documentprocess_cc_df_transportTool: '', //运输工具
            documentprocess_cc_df_delNO: '', //提运单号
            documentprocess_cc_df_recordNO: '', //备案号
            documentprocess_cc_df_tradeCountry: '', //贸易国
            documentprocess_cc_df_destCountry: '', //运抵国
            documentprocess_cc_df_specPort: '', //指运港
            documentprocess_cc_df_yardGoods: '', //境内货源
            documentprocess_cc_df_license: '', //许可证
            documentprocess_cc_df_tradeTerms: '', //成交方式
            documentprocess_cc_df_freight: '', //运费
            documentprocess_cc_df_premium: '', //保费
            documentprocess_cc_df_otherCharge: '', //杂费
            documentprocess_cc_df_contractNO: '', //合同编号
            documentprocess_cc_df_numbers: '', //件数
            documentprocess_cc_df_cartons: 'PKGS', //包装种类
            documentprocess_cc_df_grossWeight: '', //毛重
            documentprocess_cc_df_netWeight: '', //净重
            documentprocess_cc_df_containerNO: '', //集装箱号
            documentprocess_cc_df_attachBills: '', //随附单据
            documentprocess_cc_df_manufacturer: '', //生产厂家
            documentprocess_cc_df_marks: '', //标记
            documentprocess_cc_df_table: [
              {
                  documentprocess_cc_df_productNO: '', //商品编号
                  documentprocess_cc_df_productName: '', //商品名称
                  documentprocess_cc_df_productDesc: '', //商品描述
                  documentprocess_cc_df_quantityAndUnit: [0, '个'], //数量个数 以及 单位
                  documentprocess_cc_df_weightAndUnit: [0, 'KGS'], //重量 以及 单位
                  documentprocess_cc_df_destnationContry: '', //最终运抵国
                  documentprocess_cc_df_price: '', //单价
                  documentprocess_cc_df_amount: '', //总价
                  documentprocess_cc_df_currency: '人民币', //货币
                  documentprocess_cc_df_LevyExemption: '照章', //征免
                  documentprocess_cc_df_productNameAndSpeci: '', //商品名称及规格型号(新添属性)
                  documentprocess_cc_df_countryOrigin: '', //原产国(新添属性)
              }
            ],
              /*新添属性*/
              documentprocess_cc_df_domesticConsignor: '', //境内发货人
              documentprocess_cc_df_exitCustoms: '', //出境关别
              documentprocess_cc_df_recordNumber: '', //备案号
              documentprocess_cc_df_overseasConsignee: '', //境外收货人
              documentprocess_cc_df_conveyanceAndVoyageNumber: '', //运输工具名称及航次号
              documentprocess_cc_df_supervisionMode: '', //监管方式
              documentprocess_cc_df_exemptingNature: '', //征免性质
              documentprocess_cc_df_departurePort: '', //离境口岸
              documentprocess_cc_df_shippingMarks: '', //标记唛码及备注
          },

          //申报要素
          documentprocess_cc_declarationElements: {
            id: '',
            formInstId: '',
            attachedFiles: [], //附件
            documentprocess_cc_de_hscode: '', //海关编码
            documentprocess_cc_de_product: '', //产品
            documentprocess_cc_de_use: '', //用途
            documentprocess_cc_de_brand: '', //品牌
            documentprocess_cc_de_description: '', //型号

            //自定义的字段
            documentprocess_cc_de_def: [
              {
                name: '',
                value: ''
              }, {
                name: '',
                value: ''
              }, {
                name: '',
                value: ''
              }, {
                name: '',
                value: ''
              }, {
                name: '',
                value: ''
              }, {
                name: '',
                value: ''
              }
            ]
          }
        },

        //向工厂索要发票
        documentprocess_askInvoice: {
          id: '',
          formInstId: '',
          attachedFiles: [],

          documentprocess_aski_receiver: '',
          documentprocess_aski_addressCode: '',
          documentprocess_aski_address: '',

          //发票信息
          documentprocess_aski_table: [
            {
              documentprocess_aski_producuts: '',
              documentprocess_aski_description: '',
              documentprocess_aski_price: '',
              documentprocess_aski_quantity: '',
              documentprocess_aski_unit: '',
              documentprocess_aski_lineAmount: ''
            }
          ]
        },

        //核销资料收集
        documentprocess_collectionData: {
          id: '',
          formInstId: '',
          attachedFiles: []
        }
      },
      allData: {},
      roles: {
          documentprocess_askInvoice: "R",
          documentprocess_cc: "R",
          documentprocess_cc_customsDeclarationBox: "R",
          documentprocess_cc_customsDeclarationContract: "R",
          documentprocess_cc_customsDeclarationInvoice: "R",
          documentprocess_cc_declarationElements: "R",
          documentprocess_cc_declarationForm: "R",
          documentprocess_cc_letterOfDelivery: "R",
          documentprocess_collectionData: "R",
          documentprocess_fd: "W",
          documentprocess_fd_confirm: "R",
          documentprocess_fd_notice: "W",
      },
      sendMenus: [],
      isShowItem: false,
      isShowSpan: false,
      tabValue: '1',
      editable: true,
      process: ['待发事项', '待办事项', '已办事项','发起流程'],
      processNumber: 3,
      hasBind: false,
      saveAndSend: true,
    }
  },

  props: {},
  components: {
    factoryDeliveryVue,
    documentMemberDeclaringCustomsVue,
    askForInvoice,
    collectionData,
    fixedForm
  },
  methods: {

    /**
     * 接收从子组件传递来的数据,更新所有的数据
     */
    udpateAllData(key, data){
      let temp = _.cloneDeep(this.allData);
      temp[key] = data;
      this.allData = temp;

      console.log("555", this.allData);
    },

    //切换选项卡切换流程
    documentProcessChoose(tab) {

    },
    specialInitialProcess() {
      let cls = event.target.classList;
      if (cls.contains("el-icon-arrow-right") && cls.contains("el-breadcrumb__separator")) return;
      let dom = document.querySelector('.initiatingprocess .routers-ctrl');
      if (dom) {
        dom.style.zIndex = '0';
      }
    }
  }
}
</script>


<style  lang="scss">
.documentprocess {

    padding: 20px;

    i.el-breadcrumb__separator {
        margin: 0 !important;
    }

    i.el-breadcrumb__separator[class*=icon] {
        margin: 0 !important;
        padding: 0 9px !important;
    }

    .operation-icon {
        position: absolute;
        right: 3px;
        top: 50%;
        transform: translate(0, -50%);
    }

    .documentprocess-fixed {
        border: 1px solid #999;
        margin-top: 20px;
    }
}
</style>
